import { findAllCategory } from '@/api/category'
import { topCategory } from '@/api/topcategory'
// 分类模块
export default {
  namespaced: true,
  state () {
    return {
      // 分类信息集合
      list: topCategory.map(item => ({ name: item })) // 变成数组中有对象形式
    }
  },
  mutations: {
    async setList (state, payload) {
      state.list = payload
    },
    show (state, theID) {
      const obj = state.list.find(item => item.id === theID.id)
      obj.open = true
    },
    hide (state, theID) {
      const obj = state.list.find(item => item.id === theID.id)
      obj.open = false
    }
  },
  actions: {
    async  getList (store) {
      const { result } = await findAllCategory()
      // console.log(result)
      store.commit('setList', result)
    }
  }
}
